home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / Kibitz / SaveBoardImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  2.5 KB  |  125 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        saveboardimage.c
  5. ** Writtem by:  Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __ERRORS__
  21. #include <Errors.h>
  22. #endif
  23.  
  24. #ifndef __UTILITIES__
  25. #include <Utilities.h>
  26. #endif
  27.  
  28.  
  29.  
  30. /*****************************************************************************/
  31.  
  32.  
  33. typedef struct TMDHdr {
  34.     OSType    fType;
  35.     short    hdrID;
  36.     short    version;
  37.     short    prRec[60];
  38.     Fixed    xOrigin;
  39.     Fixed    yOrigin;
  40.     Point    xScale;
  41.     Point    yScale;
  42.     short    atrState[31];
  43.     short    lCnt;
  44.     short    lTot;
  45.     long    lSiz;
  46.     Rect    lR2D;
  47.     short    filler1[145];
  48. } TMDhdr;
  49.  
  50. static TMDhdr    boardHeader = {
  51.     'PICT',
  52.     0x0000        /* NOT MacDraw II specific data.  Just simple PICT. */
  53. };
  54.  
  55. extern short    gPrintPage;
  56.  
  57.  
  58.  
  59. /*****************************************************************************/
  60.  
  61.  
  62.  
  63. #pragma segment File
  64. OSErr    SaveBoardImage(FileRecHndl frHndl)
  65. {
  66.     StandardFileReply    reply;
  67.     FInfo                finfo;
  68.     WindowPtr            oldPort;
  69.     Rect                boardRect;
  70.     short                fileRefNum;
  71.     PicHandle            boardImage;
  72.     long                count;
  73.     OSErr                err;
  74.  
  75.     reply.sfFile.name[0] = 0;
  76.     if (!DisplayPutFile(&reply)) return(userCanceledErr);        /* User canceled the save. */
  77.  
  78.     err = Create_OpenFile(&reply.sfFile, &fileRefNum, 'PICT');
  79.     if (err) return(err);        /* Oops. */
  80.  
  81.     HGetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  82.     finfo.fdCreator = 'ttxt';
  83.     HSetFInfo(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, &finfo);
  84.  
  85.     oldPort = SetFilePort(frHndl);
  86.  
  87.     boardRect = BoardRect();
  88.     InsetRect(&boardRect, -1, -1);
  89.     boardImage = OpenPicture(&boardRect);
  90.     if (!boardImage) {
  91.         SetPort(oldPort);
  92.         return(memFullErr);
  93.     }
  94.  
  95.     ImageBoardLines(1, kBoardHOffset, kBoardVOffset);
  96.     gPrintPage = -1;
  97.     ImageDocument(frHndl, true);
  98.     gPrintPage = 0;
  99.  
  100.     ClosePicture();
  101.  
  102.     err = SetFPos(fileRefNum, fsFromStart, 0);
  103.         /* Set the file position to the beginning of the file. */
  104.  
  105.     if (!err) {
  106.         count = sizeof(TMDhdr);
  107.         err   = FSWrite(fileRefNum, &count, (Ptr)&boardHeader);
  108.     }
  109.  
  110.     if (!err) {
  111.         HLock((Handle)boardImage);
  112.         count = GetHandleSize((Handle)boardImage);
  113.         err   = FSWrite(fileRefNum, &count, (Ptr)*boardImage);
  114.     }
  115.     KillPicture(boardImage);
  116.  
  117.     FSClose(fileRefNum);
  118.     SetPort(oldPort);
  119.  
  120.     return(err);
  121. }
  122.  
  123.  
  124.  
  125.